package cn.imokay.juc;

import java.util.concurrent.CountDownLatch;
//减少计数
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        //例子：6个人走后，才可锁门

        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            int finalI = i;
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+(finalI+1)+"号人离开");
                countDownLatch.countDown();
            },finalI+1+"号：   ").start();
        }

        //减少为0后会被唤醒
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"：锁门");
    }
}
